<extend name="layout/edit" />

<block name="HEADER">

</block>

<block name="CONTENT">
    <control:form id="form"/>
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){
            if(__mode!=1){
            	$("#btnSave,#btnAdd").hide();
            }
		}
		
		//添加店铺
		ns.addShop = function(){
            var filter = {
                url:"modules/common/selectShop",
                mode:1,
                type:2,
                can_shop_id: $.map(form.$grids['shopGrid'].getRows(), function(h) {
	            	return h.id;
	            }).join(',')
            }
            $.openIframe(filter,"选择店铺",['600px', '480px']);
		}
        ns.selectShopsCallback = function(ids,data){
            form.$grids['shopGrid'].addRow(data);
        }
        
        //删除行
        ns.delRow = function(ids,data){
            form.$grids['shopGrid'].deleteRow();
        }
    	
        //保存
        ns.save=function(){
        	var data = form.getData();
        	if(!data) return false;
        	data.apply_shop_ids = $.map(form.$grids['shopGrid'].getRows(), function(h) {
	            	return h.id;
	        }).join(',');
        	$.ajaxs('/admin/v1/user_member_card/create',data).then(function(res){
        		form.opener.$.toast(1,'成功！');
        		form.opener.grid.load();
        		$.close();
        	});
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



